var _api = _interopRequireDefault(require("../../../utils/api")), _util2 = _interopRequireDefault(require("../../../utils/util")), _radarUtil = require("../../../utils/radar-util"), _util3 = _interopRequireDefault(require("../../../public/utils/util"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var tagReg = /<span style='(.+?)'>(.+?)<\/span>/gim, LIMIT = 20;

Component({
    properties: {
        isgoto: {
            type: Boolean,
            value: !0
        },
        uid: String,
        card: Object,
        fromuid: String,
        emptyStyle: String
    },
    data: {
        list: []
    },
    ready: function() {
        this.offset = 0;
    },
    methods: {
        onPullDownRefresh: function() {
            this.loadList(!0, wx.stopPullDownRefresh);
        },
        onReachBottom: function() {
            this.data.noMore || this.loadList();
        },
        loadList: function(e, t) {
            var i = this;
            e && (this.offset = 0);
            var a = this.data, o = a.uid, r = a.fromuid;
            _api.default.market.log.lists({
                data: {
                    uid: o,
                    fromuid: r,
                    offset: this.offset,
                    limit: LIMIT
                },
                complete: t
            }).then(function(t) {
                return i.formatVisitorList(e, t.data);
            });
        },
        getFormatDate: function(t) {
            return _util3.default.formatLocalDate(t, _util3.default.isToday(1e3 * t) ? "h:m" : "Y-M-D", 0);
        },
        formatVisitorList: function(t, e) {
            var i = this, a = e.lists, o = e.count, r = {
                noMore: (a = a.map(function(t) {
                    return t.content.content = t.content.content.replace(t.realname, ""), t.formatDate = i.getFormatDate(t.createtime), 
                    t.contents = _util2.default.regExpSeparateLabels(t.content.content, tagReg), t;
                })).length < LIMIT
            };
            if (t) r.list = [ a ]; else {
                var n = (this.data.list || []).length;
                r["list[".concat(n, "]")] = a;
            }
            this.setData(r), this.offset += LIMIT, t && this.triggerEvent("count", {
                count: o
            }, {});
        },
        gotoChat: function(t) {
            var e = t.currentTarget.dataset, i = e.name, a = e.uid, o = this.data, r = o.isgoto, n = o.card;
            if (r) {
                var u = n ? n.cardid : "";
                (0, _radarUtil.gotoChatRoom)({
                    name: i,
                    cardid: u,
                    touid: a
                });
            }
        }
    }
});